﻿using System.Xml;

namespace Jayden.Dll.Sc2.Descriptions
{
	public class UpgradeActionDescription : BuildActionDescription
	{
		protected UpgradeActionDescription(EntityDescription entity, EntityDescription build, string id)
			: base(entity, build, id) { }
		public UpgradeActionDescription(EntityDescription entity, XmlNode node, string format = "{0}UpgradeTo{1}", string nameFormat = "{0} upgrade to {1}")
			: base(entity, node, format, nameFormat) { }

		public override void Execute(GameState state)
		{
			RemoveResources(state);
			state.Add(Entity, 0, -1, -1);
			state.Add(Build, 1, 0, 1);
			if (Entity == Entity.Race.Base && Build.IsBase)
				state.Bases++;
			BaseExecute(state);
			state.Add(new DelayedActionDescription(this, Build.Time + state.Time, delegate(GameState innerState)
			{
				state.Add(Build, -1, 1, 0);
			}));
		}

	}

}
